<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title id="adminTile"></title>
    <!--    <link rel="icon" href="assets/images/zhi_favicon.ico"/>-->
    <link rel="icon" id="linkHref" href="" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1"
    />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" href="assets/libs/layui/css/layui.css" />
    <link rel="stylesheet" href="assets/module/admin.css?v=307" />
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
      /*.main-body {top:50%;left:50%;position:absolute;-webkit-transform:translate(-50%,-50%);-moz-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);-o-transform:translate(-50%,-50%);transform:translate(-50%,-50%);overflow:hidden;}*/
      .login-main .login-bottom .center .item input {
        display: inline-block;
        width: calc(100% - 22px);
        height: 58px;
        padding-left: 20px;
        position: absolute;
        outline: 0;
        font-size: 16px;
        letter-spacing: 0;
        background: #f8f9fa;
        border-radius: 8px;
        border: 1px solid #dfe4e9;
      }
      .login-main .login-bottom .center .item .icon-1 {
        background: url(assets/images/icon-login.png) no-repeat 1px 0;
      }
      .login-main .login-bottom .center .item .icon-2 {
        background: url(assets/images/icon-login.png) no-repeat -54px 0;
      }
      .login-main .login-bottom .center .item .icon-3 {
        background: url(assets/images/icon-login.png) no-repeat -106px 0;
      }
      /*.login-main .login-bottom .center .item .icon-4 {background:url(assets/images/icon-login.png) no-repeat 0 -43px;position:absolute;right:-10px;cursor:pointer;}*/
      .login-main .login-bottom .center .item .icon-5 {
        background: url(assets/images/icon-login.png) no-repeat -55px -43px;
      }
      .login-main .login-bottom .center .item .icon-6 {
        background: url(assets/images/icon-login.png) no-repeat 0 -93px;
        position: absolute;
        right: -10px;
        margin-top: 8px;
        cursor: pointer;
      }
      .login-main .login-bottom .tip .icon-nocheck {
        display: inline-block;
        width: 10px;
        height: 10px;
        border-radius: 2px;
        border: solid 1px #9abcda;
        position: relative;
        top: 2px;
        margin: 1px 8px 1px 1px;
        cursor: pointer;
      }
      .login-main .login-bottom .tip .icon-check {
        margin: 0 7px 0 0;
        width: 14px;
        height: 14px;
        border: none;
        background: url(assets/images/icon-login.png) no-repeat -111px -48px;
      }
      .login-main .login-bottom .center .item .icon {
        cursor: pointer;
        display: inline-block;
        width: 24px;
        height: 24px;
        position: absolute;
        top: 20px;
        right: 20px;
        transition: all 0.3s;
        background-image: url(assets/images/close-eye.png);
        background-size: 100% 100%;
      }
      .login-main .login-bottom .center .item .icon.open {
        background-image: url(assets/images/open-eye.png);
        background-size: 100% 100%;
      }
      .login-main .login-bottom .center .item {
        width: 100%;
        height: 58px;
        margin-bottom: 35px;
        position: relative;
      }
      .login-main .login-top {
        height: 117px;
        background-color: #148be4;
        border-radius: 12px 12px 0 0;
        font-family: SourceHanSansCN-Regular;
        font-size: 30px;
        font-weight: 400;
        font-stretch: normal;
        letter-spacing: 0;
        color: #fff;
        line-height: 117px;
        text-align: center;
        overflow: hidden;
        -webkit-transform: rotate(0);
        -moz-transform: rotate(0);
        -ms-transform: rotate(0);
        -o-transform: rotate(0);
        transform: rotate(0);
      }
      .login-main .login-top .bg1 {
        display: inline-block;
        width: 74px;
        height: 74px;
        background: #fff;
        opacity: 0.1;
        border-radius: 0 74px 0 0;
        position: absolute;
        left: 0;
        top: 43px;
      }
      .login-main .login-top .bg2 {
        display: inline-block;
        width: 94px;
        height: 94px;
        background: #fff;
        opacity: 0.1;
        border-radius: 50%;
        position: absolute;
        right: -16px;
        top: -16px;
      }
      .login-main .login-bottom,
      .login-main .copyright {
        max-width: 450px;
        background: #fff;
        border-radius: 0 0 12px 12px;
      }
      .login-main .login-bottom .center {
        width: 100%;
        margin: 0 auto;
        padding-top: 40px;
        padding-bottom: 15px;
        position: relative;
      }
      .login-main .login-bottom .tip {
        clear: both;
        height: 16px;
        line-height: 16px;
        width: 288px;
        margin: 0 auto;
      }
      body {
        background: url(assets/images/login_bg.png) 0% 0% / cover no-repeat;
        position: static;
        font-size: 12px;
      }
      input::-webkit-input-placeholder {
        color: #a6aebf;
      }
      input::-moz-placeholder {
        /* Mozilla Firefox 19+ */
        color: #a6aebf;
      }
      input:-moz-placeholder {
        /* Mozilla Firefox 4 to 18 */
        color: #a6aebf;
      }
      input:-ms-input-placeholder {
        /* Internet Explorer 10-11 */
        color: #a6aebf;
      }
      input:-webkit-autofill {
        /* 取消Chrome记住密码的背景颜色 */
        -webkit-box-shadow: 0 0 0 1000px #f8f9fa inset !important;
      }
      html {
        height: 100%;
      }
      .login-main .login-bottom .tip {
        clear: both;
        height: 16px;
        line-height: 16px;
        width: 288px;
        margin: 0 auto;
      }
      .login-main .login-bottom .tip .login-tip {
        font-family: MicrosoftYaHei;
        font-size: 12px;
        font-weight: 400;
        font-stretch: normal;
        letter-spacing: 0;
        color: #9abcda;
        cursor: pointer;
      }
      .login-main .login-bottom .tip .forget-password {
        font-stretch: normal;
        letter-spacing: 0;
        color: #1391ff;
        text-decoration: none;
        position: absolute;
        right: 62px;
      }
      .login-main .login-bottom .login-btn {
        width: 100%;
        height: 58px;
        background-color: #0f54f0;
        border-radius: 8px;
        margin: 24px auto 0;
        text-align: center;
        line-height: 40px;
        color: #fff;
        font-size: 24px;
        letter-spacing: 2px;
        cursor: pointer;
        border: none;
      }
      .login-main .login-bottom .center .item .validateImg {
        position: absolute;
        right: 17px;
        cursor: pointer;
        height: 40px;
        top: 10px;
      }
      .footer {
        left: 0;
        bottom: 0;
        color: #fff;
        width: 100%;
        position: absolute;
        text-align: center;
        line-height: 30px;
        padding-bottom: 10px;
        text-shadow: #000 0.1em 0.1em 0.1em;
        font-size: 14px;
      }
      .padding-5 {
        padding: 5px !important;
      }
      .footer a,
      .footer span {
        color: #fff;
      }
      /*@media screen and (max-width:428px) {.login-main {width:360px !important;}*/
      /*.login-main .login-top {width:360px !important;}*/
      /*.login-main .login-bottom {width:360px !important;}*/
      /*}*/
      body,
      .main-body {
        height: 100%;
      }
      .main-body {
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .login-content {
        height: 700px;
        width: 1500px;
        box-sizing: border-box;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .login-content .login-bg {
        width: 100%;
        height: 100%;
        padding: 30px;
        border-radius: 40px;
        background-color: #ffffff;
        box-shadow: 0 4px 65px 3px rgba(12, 63, 198, 0.1);
      }
      .login-content .login-main {
        width: 100%;
        height: 100%;
        display: flex;
      }
      .login-content .login-main .login-left {
        width: 50%;
      }
      .login-content .login-right {
        width: 50%;
      }
      .login-content .login-main .login-left img {
        width: 100%;
        height: 100%;
      }
      .login-right .login-log {
        padding: 120px 0 0;
      }
      .login-right .login-log img {
        width: 420px;
        height: 77px;
      }
      .login-right .model-box {
        padding-left: 130px;
      }
      .login-title {
        font-size: 32px;
        color: #1a2233;
        font-weight: 600;
        letter-spacing: 3px;
        padding-top: 50px;
      }
      .login-main .login-bottom .login-btn:hover {
        opacity: 0.8;
        transition: all 0.3s;
      }
      .page-loading {
        display: none;
        background-color: rgba(0, 0, 0, 0.15);
        cursor: pointer;
      }
      .page-loading .ball-loader {
        left: calc(50% + 351px);
      }
      .layui-layer-msg {
        width: 180px !important;
        top: 50%;
        border-radius: 8px !important;
        left: calc(50% + 251px) !important;
      }
      @media (max-width: 1680px) {
        .login-content {
          height: 680px;
          width: 1300px;
        }
      }
      .login-main .copyright,
      .login-main .copyright .technicalSupport > a {
        margin-top: 30px;
        font-size: 14px;
        color: #666;
      }
      .login-main .copyright:after {
        content: "";
        display: block;
        clear: none;
      }
      .login-main .copyright .company {
        float: left;
      }
      .login-main .copyright .technicalSupport {
        float: right;
      }
    </style>
  </head>
  <body>
    <div class="main-body">
      <div class="login-content">
        <div class="login-bg">
          <div class="login-main">
            <div class="login-left">
              <img src="assets/images/login_lt.png" alt="" />
            </div>
            <div class="login-right">
              <div class="model-box">
                <div class="login-log">
                  <img src="" id="loginBackgroundLogo" style="opacity: 0" />
                </div>
                <form class="layui-form login-bottom">
                  <input type="hidden" name="captchaKey" />
                  <div class="center">
                    <div class="item">
                      <input
                        type="text"
                        name="username"
                        lay-verify="required"
                        placeholder="请输入登录账号"
                        maxlength="24"
                      />
                    </div>

                    <div class="item">
                      <input
                        type="password"
                        name="password"
                        lay-verify="required"
                        placeholder="请输入密码"
                        maxlength="20"
                      />
                      <span class="bind-password icon" id="bindPassword"></span>
                    </div>

                    <div id="validatePanel" class="item">
                      <input
                        type="text"
                        name="captcha"
                        placeholder="请输入验证码"
                        maxlength="4"
                      />
                      <img id="refreshCaptcha" class="validateImg" />
                    </div>
                  </div>
                  <!--            <div class="tip">-->
                  <!--                <span class="icon-nocheck"></span>-->
                  <!--                <span class="login-tip">保持登录</span>-->
                  <!--                <a href="javascript:" class="forget-password">忘记密码？</a>-->
                  <!--            </div>-->
                  <div
                    class="layui-form-item"
                    style="
                      text-align: center;
                      width: 100%;
                      height: 100%;
                      margin: 0px;
                    "
                  >
                    <button class="login-btn" lay-submit="" lay-filter="login">
                      登录
                    </button>
                  </div>
                </form>
                <div
                  class="copyright"
                  style="display: flex; justify-content: space-between"
                >
                  <div class="company">
                    &copy; Copyright<span id="company"></span>
                  </div>
                  <div
                    class="technicalSupport"
                    style="padding-left: 20px; flex-shrink: 0"
                  >
                    技术支持：<a href="javascript:;">云端智造</a>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 加载动画 -->
    <div class="page-loading">
      <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
      </div>
    </div>
    <!--<div class="footer">-->
    <!--    ©版权所有 2014-2018 叁贰柒工作室<span class="padding-5">|</span><a target="_blank" href="http://www.miitbeian.gov.cn">粤ICP备16006642号-2</a>-->
    <!--</div>-->
    <script type="text/javascript" src="assets/libs/layui/layui.js"></script>
    <script
      type="text/javascript"
      src="assets/libs/jquery/jquery-3.2.1.min.js"
    ></script>
    <script
      type="text/javascript"
      src="assets/libs/jquery/jquery.md5.js"
    ></script>
    <script>
      layui
        .config({
          base: "assets/module/",
        })
        .use(["layer", "form", "config", "admin"], function () {
          var $ = layui.jquery;
          var layer = layui.layer;
          var form = layui.form;
          var config = layui.config;
          var admin = layui.admin;
          var origin = window.location.href;
          var urlCode = origin.substr(origin.lastIndexOf("//") + 2, 5);
          // var backgroundLogo = urlCode === 'z0001' ? 'assets/images/jc-logo.png' : (urlCode === 'z0003' || urlCode === 'z0016') ? 'assets/images/yunduan-logo.png' : 'assets/images/wrf-logo.png';
          var backgroundLogo = "assets/images/initial-logo.png";
          // var adminTile = urlCode === 'z0001' ? '劲驰智能工具柜' : (urlCode === 'z0003' || urlCode === 'z0016') ? '云端智能工具柜' : '沃尔孚智能工具柜'
          var adminTile = "智能柜";

          getCaptcha();

          // 表单提交
          form.on("submit(login)", function (obj) {
            var data = obj.field;
            if (data.username == "") {
              layer.msg("用户名不能为空");
              return false;
            }
            if (data.password == "") {
              layer.msg("密码不能为空");
              return false;
            }
            if (data.captcha == "" || data.captcha.trim() == "") {
              $('input[name="captcha"]').val("");
              layer.msg("验证码不能为空");
              return false;
            }
            admin.showLoading();
            data.grant_type = "password";
            data.scope = "web";
            data.client_id = "webApp";
            data.client_secret = "webApp";
            //密码加密
            data.password = $.md5(data.password);
            console.info($.md5(data.password));
            console.info(data);
            var origin = window.location.href;
            var urlCode = origin.substr(origin.lastIndexOf("//") + 2, 5);
            var menuIndex = urlCode == "e0036" ? 0 : "";
            $.post(
              config.base + "oauth2/admin/user/login",
              data,
              function (res) {
                admin.removeLoading();
                if (200 == res.code) {
                  config.putToken(res.data.token);
                  config.putTempData("menuIndex", menuIndex);
                  setTimeout(() => {
                    goIndex();
                  }, 500);
                } else {
                  layer.msg(res.msg);
                  // 重置验证码
                  getCaptcha();
                }
              },
              "json"
            );
            return false;
          });

          // 获取验证码
          function getCaptcha() {
            $.ajax({
              url: config.base + "oauth2/admin/user/getCaptcha",
              type: "GET",
              success: function (res) {
                if (res.code == 200) {
                  $("input[name='captcha']").val("");
                  $("input[name='captchaKey']").val(res.data.captchaKey);
                  $(".validateImg").attr("src", res.data.captchaImage);
                }
              },
            });
          }

          function goIndex() {
            // window.location.reload(true);
            location.replace("/admin/index.html");
          }

          // 图形验证码
          $(".validateImg").click(function () {
            getCaptcha();
          });

          //打开关闭
          $("#bindPassword").click(function () {
            let ipt = $("input[name='password']");
            if (ipt.attr("type") == "password") {
              ipt.attr("type", "text");
              $(this).addClass("open");
            } else {
              $(this).removeClass("open");
              ipt.attr("type", "password");
            }
            // console.log(.attr('type'))
          });

          // 查询logo、版权信息等

          $.ajax({
            url:
              config.base +
              "enterprise/system/admin/systemOfficialInfo/getInfo",
            type: "GET",
            success: function (res) {
              if (res.code === 200) {
                config.putTempData('companyName', res.data.companyName);
                if (res.data.backgroundLogo) {
                  // backgroundLogo = res.data.backgroundLogo;
                  $("#company").text(res.data.copyright);
                }
                if (res.data.sysName) {
                  adminTile = res.data.sysName;
                }
              }
              // $('#loginBackgroundLogo').attr('src', backgroundLogo);
              // $('#loginBackgroundLogo').css('opacity', 1);
              $("#linkHref").attr("href", res.data.icon);
              $("#adminTile").html(adminTile);
            },
            error: function (res) {
              /* $('#loginBackgroundLogo').attr('src', backgroundLogo);
                $('#loginBackgroundLogo').css('opacity', 1);*/
            },
          });

          $.ajax({
            url:
              config.base +
              "enterprise/system/admin/systemOfficialInfo/getEnterpriseCode?enterpriseCode=" +
              getSubdomain(),
            type: "GET",
            success: function (res) {
              if (res.code === 200) {
                if (res.data.foregroundLogo) {
                  backgroundLogo = res.data.foregroundLogo;
                }
                /*if (res.data.sysName) {
                        adminTile = res.data.sysName;
                    }*/
              }
              $("#loginBackgroundLogo").attr("src", backgroundLogo);
              $("#loginBackgroundLogo").css("opacity", 1);
              // $("#adminTile").html(adminTile);
            },
            error: function (res) {
              $("#loginBackgroundLogo").attr("src", backgroundLogo);
              $("#loginBackgroundLogo").css("opacity", 1);
            },
          });

          /**
           * 获取当前 URL 二级域名
           * 如果当前是 IP 地址，则直接返回 IP Address
           */
          function getSubdomain() {
            try {
              let subdomain = "";
              const { domain } = document;
              const domainList = domain.split(".");
              const ipAddressReg =
                /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
              // 若为 IP 地址、localhost，则直接返回
              if (ipAddressReg.test(domain) || domain === "localhost") {
                return domain;
              }

              /* const urlItems = [];
                urlItems.unshift(domainList.pop());*/

              /*while (domainList.length) {
                    urlItems.unshift(domainList.pop());
                    subdomain = urlItems.join('.');
                }*/
              subdomain = domainList[0] || document.domain;

              return subdomain;
            } catch (e) {
              return document.domain;
            }
          }
        });
    </script>
  </body>
</html>
